<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card :bordered="false">
      <!-- <title-name title="固定资产调拨" /> -->
      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
      >
        <template
          slot="prefix"
        >
          <a-button
            type="primary"
            icon="plus"
            @click="$nav('add')"
          >
            调拨申请
          </a-button>
        </template>
        <span
          slot="index"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <template
          slot="auditStatus"
          slot-scope="text, record"
        >
          <list-status
            :status="record.auditStatus"
            :text="text"
            conversion="no"
            :is-approval="true"
          />
        </template>
        <template
          slot="operation"
          slot-scope="text, record"
        >
          <MoreButton>
            <a @click="$nav('add',{id:record.id,detail:1})">查看</a>
            <template v-if="record.auditStatus === 'DRAFT'||record.auditStatus === 'REJECTED'">
              <a @click="$nav('add',{id:record.id})">编辑</a>
            </template>
            <template v-if="record.auditStatus === 'DRAFT'">
              <a @click="handleDel(record.id)">删除</a>
            </template>
            <!--                        <span @click="handleDel(record.id)">删除</span>-->

            <approval-button
              :id="record.id"
              :status="record.auditStatus"
              text="审批信息"
              v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'REVOKEIN' || record.auditStatus === 'REVOKE' || record.auditStatus === 'ABOLISH' || record.auditStatus === '1' || record.auditStatus === '3' || record.auditStatus === 'COMMIT'|| record.auditStatus === '2' "
            />
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import assetApi from '@/api/office/asset'
import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject'
import SelectPerson from '@/components/Select/SelectPerson'
import SelectOrgPeople from '@/components/Select/SelectOrgPeople'
import OrgTreeSelect from '@/components/OrgTreeSelect'

export default {
  name:'AssetManagementTransferIndex',
    data() {
        return {
            columns: [
                {
                    title: '序号',
                    dataIndex: 'index',
                    width: 70,
                    scopedSlots: { customRender: 'index' }
                },
                {
                    title: '资产编号',
                    dataIndex: 'assetCode',
                    width: 150
                },
                {
                    title: '资产名称',
                    dataIndex: 'assetName',
                    width: 120
                },
                {
                    title: '单位',
                    dataIndex: 'unit',
                    width: 250
                },
                {
                    title: '原值(元)',
                    dataIndex: 'originalValue',
                    width: 100
                },
                {
                    title: '调出单位',
                    dataIndex: 'assetTransferOut.transferOutDepName',
                    width: 250
                },
                {
                    title: '调入单位',
                    dataIndex: 'assetTransferIn.transferInDepName',
                    width: 250
                },
                {
                    title: '申请单位',
                    dataIndex: 'applicantDepName',
                    width: 250
                },
                {
                    title: '申请人',
                    dataIndex: 'applicantName',
                    width: 150
                },
                {
                    title: '状态',
                    dataIndex: 'auditStatus',
                    scopedSlots: { customRender: 'auditStatus' },
                    width: 150
                },
                {
                    title: '操作',
                    width: 220,
                    fixed: 'right',
                    scopedSlots: { customRender: 'operation' }
                }
            ],
            searchArr: [
                // 搜索框
                {
                  name: '申请单位',
                  valueKey: 'searchQuery',
                  type: OrgTreeSelect,
                  attrs: {
                    isAutoSelectFirst: true,
                    isNeedOrgId:true
                  }
                },
                // {
                //     name: '申请单位',
                //     type: SelectCompanyAndProject,
                //     valueKey: 'applicantDepId',
                //     isAuth: false,
                //     isAutoSelectMe: true
                // },
                {
                    name: '申请人',
                    valueKey: 'applicantId',
                    keyValue: 'searchQuery._checked',
                    type: SelectOrgPeople,
                    placeholder: '请输入',
                    isOrgIdNotNull: true,
                    isAutoSelectMe: true,
                    isSearch: true
                },
                {
                    name: '资产名称',
                    value: 'assetName',
                    type: 'input'
                },
                {
                    name: '资产编号',
                    value: 'assetCode',
                    type: 'input'
                },
                {
                    name: '状态',
                    value: 'auditStatus',
                    type: 'select',
                    data: [
                        { label: '待提交审批', value: 'DRAFT', enabled: true },
                        { label: '审批中', value: 'SUBMITTED', enabled: true },
                        { label: '审批通过', value: 'PAST', enabled: true },
                        { label: '审批不通过', value: 'REJECTED', enabled: true },
                        // { label: '已撤销', value: 'REVOKE', enabled: true },
                        // { label: '撤销中', value: 'REVOKEIN', enabled: true }
                    ]
                }
            ],
            loadData: (params) => {
                return assetApi.assetTransfersList(Object.assign(params, { query: this.queryParam }))
            },
            queryParam: {
                searchQuery: { _checked: this.$currentPost().id },
                applicantDepId: this.$currentPost().id,
                applicantId: this.$userInfo().id
            }
        }
    },
    methods: {
        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        },
        handleDel(id) {
            this.$delList3(assetApi.assetTransfersDel, () => {
                this.search()
            }, { id })
        }
    }
}
</script>
